package org.shijiagen.order.controller;

import lombok.RequiredArgsConstructor;
import org.shijiagen.order.service.OrderService;
import org.shijiagen.param.CartListParam;
import org.shijiagen.param.OrderParam;
import org.shijiagen.param.PageParam;
import org.shijiagen.utils.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order")
@RequiredArgsConstructor
public class OrderController {

    private final OrderService orderService;

    @PostMapping("list")
    public R list(@RequestBody @Validated CartListParam cartListParam){
        return R.ok("订单数据获取成功",orderService.list(cartListParam.getUserId()));
    }

    @PostMapping("save")
    public R save(@RequestBody OrderParam orderParam){
        orderService.save(orderParam);
        return R.ok("订单生成成功");
    }

    @PostMapping("remove/check")
    public R removeCheck(Integer productId){
        return orderService.check(productId);
    }

    @PostMapping("admin/list")
    public R adminList(@RequestBody PageParam pageParam){
        return orderService.adminList(pageParam);
    }
}
